package resources.urlresource;

import org.junit.jupiter.api.Test;
import org.springframework.core.io.FileSystemResource;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLOutput;

//访问系统中的资源
public class FileSystemResourceDemo {
    @Test
    public void TestFileSystemResource(){
        //相对路径
        //绝对路径
        loadFileResource("D:\\Code Resource\\Spring6FileSystemResource.txt");
    }
    public static void loadFileResource(String path) {
        //创建对象
        FileSystemResource resource = new FileSystemResource(path);
        System.out.println(resource.getDescription());
        System.out.println(resource.getFilename());
        try {
            InputStream in = resource.getInputStream();
            byte[] b = new byte[1024];
            while (in.read(b)!=-1){
                System.out.println(new String(b));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
